package Jtree;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.tree.DefaultMutableTreeNode;

import db.DBUtil;

public class TreeDAO {
	public  void createNodes(DefaultMutableTreeNode parent, String ParentID) throws SQLException {
		Connection conn = DBUtil.getConnection();
		Statement stmt = conn.createStatement();
		DefaultMutableTreeNode temp = null;
		String strsql = "select unit_id,unit_name ,up_unit_id from t_base_unit_info where  up_unit_id ='" + ParentID + "'";
		int i = 0;
		try {
			ResultSet rs = stmt.executeQuery(strsql);
			while (rs.next()) {
				i++;
				temp = new DefaultMutableTreeNode(rs.getString("unit_name"));
				parent.add(temp);
				createNodes(temp, rs.getString("unit_id"));
				rs = stmt.executeQuery(strsql);
				rs.relative(i);
			}
		} catch (Exception e) {
			System.out.println(e);
		}
		DBUtil.close(conn);
	}

}
